import java.util.ArrayList;

/**
 * Project: SecuritySnort
 * This class takes care of the command to specify
 * where packets are displayed/stored.
 *
 * @author Jonathan Buttner
 * @version Jan 26, 2010
 */
public class SavePackCmd extends Command
{
	/**************************************************************************
	 * 							Globals
	 *************************************************************************/
	private CaptureCmd _capture;
	private final String DEFAULT_FNAME = "DEFAULT_CapturedPacks";
	
	/**************************************************************************
	 * 							Constructors
	 *************************************************************************/
	
	/**
	 * This constructor will setup the correct objects.
	 */
	public SavePackCmd( CaptureCmd capture )
	{
		_capture = capture;
		_name = "OutputTo";
	}
	
	/**************************************************************************
	 * 							Public Methods
	 *************************************************************************/
	
	/**
	 * This method will set the filename specified by the command
	 * given by the user or it can specify where the packet is to
	 * be displayed: Console, File, or Both.
	 * 
	 * @param command is an ArrayList of Strings holding the
	 * tokenized command given by the user.
	 */
	public void exeCommand( ArrayList < String > command )
	{
		if ( command.get(1).equalsIgnoreCase("-d") )
		{
			_capture.setOutput( OutputTo.DISP );
			System.out.println( "\nOutputting received packets to the console." );
		}
		else if ( command.get(1).equalsIgnoreCase( "-f" ) )
		{
			if ( command.size() == 2 )
			{
				_capture.setOutput( OutputTo.FILE );
				_capture.setFilename( DEFAULT_FNAME );
				System.out.println( "\nOutputting received packets to the file:" +
						"\n" + DEFAULT_FNAME );
			}
			else
			{
				_capture.setOutput( OutputTo.FILE );
				_capture.setFilename( command.get( 2 ) );
				System.out.println( "\nOutputting received packets to the file:" +
						"\n" + command.get(2) );
			}
		}
		else if ( command.get( 1 ).equalsIgnoreCase( "-b" ) )
		{
			if ( command.size() == 2 )
			{
				_capture.setOutput( OutputTo.BOTH );
				_capture.setFilename( DEFAULT_FNAME );
				System.out.println( "\nOutputting received packets to the file:" +
						"\n" + DEFAULT_FNAME + "\nAnd to the console." );
			}
			else
			{
				_capture.setOutput( OutputTo.BOTH );
				_capture.setFilename( command.get( 2 ) );
				System.out.println( "\nOutputting received packets to the file:" +
						"\n" + command.get(2) + "\nAnd to the console." );
			}
		}
	}
}
